<template>
  <div class="warehouse-container">
    <!-- 查询表单 -->
    <el-form :model="queryForm" ref="queryFormRef" :inline="true" class="query-form" label-width="auto">
      <el-form-item label="仓库名字" prop="name">
        <el-input v-model="queryForm.name" placeholder="请输入仓库名字" clearable />
      </el-form-item>
      
      <el-form-item label="负责人名字" prop="personChargeName">
        <el-input v-model="queryForm.personChargeName" placeholder="请输入负责人名字" clearable />
      </el-form-item>
      
      <el-form-item label="所在省份" prop="provinceName">
        <el-input v-model="queryForm.provinceName" placeholder="请输入所在省份" clearable />
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" @click="handleQuery">查询</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    
    <!-- 数据表格 -->
    <el-table :data="warehouseList" border style="width: 100%" v-loading="loading">
      <el-table-column prop="name" label="仓库名字" min-width="150" />
      <el-table-column prop="cityName" label="所在城市名称" min-width="120" />
      <el-table-column prop="provinceName" label="所在省份名字" min-width="120" />
      <el-table-column prop="address" label="详细地址" min-width="200" />
      <el-table-column prop="personChargeName" label="负责人名字" min-width="120" />
      <el-table-column prop="saasId" label="SaaS标识" min-width="150" />
      
      <template #empty>
        <el-empty description="暂无数据" />
      </template>
    </el-table>
    
    <!-- 分页 -->
    <el-pagination
      v-model:current-page="pagination.currentPage"
      v-model:page-size="pagination.pageSize"
      :page-sizes="[10, 20, 50, 100]"
      :total="pagination.total"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      class="pagination"
    />
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'

// 查询表单数据
const queryForm = ref({
  name: '',
  personChargeName: '',
  provinceName: ''
})

// 表格数据
const warehouseList = ref([])
const loading = ref(false)

// 分页信息
const pagination = ref({
  currentPage: 1,
  pageSize: 10,
  total: 0
})

// 查询表单引用
const queryFormRef = ref(null)

// 获取仓库列表数据
const getWarehouseList = async () => {
  loading.value = true
  try {
   
    
    // 模拟数据
    warehouseList.value = [
      {
        id: 1,
        name: '北京一号仓库',
        cityName: '北京市',
        provinceName: '北京市',
        address: '北京市朝阳区某某街道123号',
        personChargeName: '张三',
        saasId: 'SAAS001'
      },
      {
        id: 2,
        name: '上海二号仓库',
        cityName: '上海市',
        provinceName: '上海市',
        address: '上海市浦东新区某某路456号',
        personChargeName: '李四',
        saasId: 'SAAS002'
      },
      {
        id: 3,
        name: '广州三号仓库',
        cityName: '广州市',
        provinceName: '广东省',
        address: '广东省广州市天河区某某大道789号',
        personChargeName: '王五',
        saasId: 'SAAS003'
      }
    ]
    
    pagination.value.total = 3
  } catch (error) {
    ElMessage.error('获取仓库列表失败')
  } finally {
    loading.value = false
  }
}

// 查询
const handleQuery = () => {
  pagination.value.currentPage = 1
  getWarehouseList()
}

// 重置查询
const resetQuery = () => {
  queryFormRef.value?.resetFields()
  pagination.value.currentPage = 1
  getWarehouseList()
}

// 分页大小改变
const handleSizeChange = (val) => {
  pagination.value.pageSize = val
  pagination.value.currentPage = 1
  getWarehouseList()
}

// 当前页改变
const handleCurrentChange = (val) => {
  pagination.value.currentPage = val
  getWarehouseList()
}

// 页面加载时获取数据
onMounted(() => {
  getWarehouseList()
})
</script>

<style scoped>
.warehouse-container {
  padding: 20px;
  background-color: #fff;
}

.query-form {
  margin-bottom: 20px;
  padding: 20px;
  background-color: #f5f7fa;
  border-radius: 4px;
}

.query-form .el-form-item {
  margin-bottom: 0;
}

.pagination {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style>